"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 功能-功能测试
Case Name   : 成功安装插件
Create At   : 2023/4/23
Owner       : n@ningyali
Description :
    1、打开插件管理页面
    2、点击右上角“安装插件”按钮
    3、将插件Jar包拖入安装窗口
    4、确认安装【结果1】【结果2】
Expect      :
    1、【结果1】提示安装成功
    2、【结果2】插件菜单出现，可打开插件Tab
History     :
"""
import os
import unittest

from openGaussMigrate.common.base import Base
from openGaussMigrate.common.com_log import ComLog
from openGaussMigrate.common.com_node import Macro
from openGaussMigrate.common.com_unit_action import ComUnitAction


class Install0001(unittest.TestCase):
    def setUp(self):
        self.log = ComLog(self.__class__.__name__)
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        web = Macro('WEB_INFO')
        self.driver = ComUnitAction(web.info['driver_path'], web.info['url'])
        self.driver.open()
        self.driver.login(web.info['user'], web.info['passwd'])
        self.plugin_name = "data-migration"
        self.plugin_name_cn = "数据迁移"
        self.plugin_path = os.path.join(os.getcwd(),
                                        'resources',
                                        'plugins',
                                        'data-migration-5.0.0-repackage.jar')

    @Base.retry(max_n=1)
    @Base.save_img_when_err(cls_name='Install0001')
    def test_case1(self):
        """成功安装插件"""
        self.driver.install_plugin(self.plugin_name_cn, self.plugin_path)

    def tearDown(self):
        try:
            self.driver.uninstall_plugin(self.plugin_name)
        except Exception as e:
            self.log.error(str(e))
        finally:
            self.driver.close()
        self.log.info('teardown run finished')
